import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


//注意 typedef 需要放在class外面 类似于OC中的block回调函数
typedef IndexCallback<int> = void Function(int index);
class SwiperDiy extends StatelessWidget {
  IndexCallback<int> onTap;
  final List swiperDateList;

  SwiperDiy(this.swiperDateList,@required this.onTap);

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);

    return Container(
      height: ScreenUtil().setHeight(300),
      width: ScreenUtil().setWidth(750),
      child: Swiper(
        itemCount: 3,
        autoplay: true,
        scrollDirection: Axis.horizontal,
        viewportFraction: 1.0,
        onTap: (index){
          this.onTap(index);
        },
        itemBuilder: (BuildContext context, int index){
          return Image.network(this.swiperDateList[index]['image_url'],fit: BoxFit.cover,);
//          return Column(
//            children: <Widget>[
//              Image.network(this.swiperDateList[index]['image_url'],fit: BoxFit.cover,),
////              Text(this.swiperDateList[index]['swiper_title'])
//            ],
//          );
        },
      ),
    );
  }
}



